package com.qianf.qfoffice.service.impl;

import com.github.pagehelper.PageHelper;
import com.qianf.qfoffice.dao.ResourceDao;
import com.qianf.qfoffice.entity.Question;
import com.qianf.qfoffice.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private ResourceDao resourceDao;

    /**
     * 添加笔记
     * @param question
     * @return
     */
    @Override
    public boolean addNote(Question question) {

        int num = resourceDao.addNote(question);

        if(num>0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 添加代码
     * @param question
     * @return
     */
    @Override
    public boolean addCode(Question question) {

        int num = resourceDao.addCode(question);

        if(num>0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 添加面试题
     * @param question
     * @return
     */
    @Override
    public boolean addSavequestion(Question question) {
        int num = resourceDao.addSavequestion(question);
        if(num>0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 分页展示所有资源
     * @param uno
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<Question> selectQuestion(String uno, Integer page, Integer limit) {

        PageHelper.startPage(page,limit);

        List<Question> questions = resourceDao.selectQuestion(uno);

        return questions;
    }

    /**
     * 删除资源
     * @param id
     * @return
     */
    @Override
    public boolean deleteQuestion(int id) {

        int num = resourceDao.deleteQuestion(id);

        if (num>0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 更新资源信息
     * @param question1
     * @return
     */
    @Override
    public boolean updateQuestion(Question question1) {

        int num = resourceDao.updateQuestion(question1);

        if(num>0){
            return true;
        }else{
            return false;
        }

    }
}
